package www.reviewW.data;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ReviewWData implements Serializable {
    private List<ModeData> modeDatas = new ArrayList<>();
    //添加栏
    public void addModeDatas(String title){
        modeDatas.add(0,new ModeData(title));
    }
    //删除栏
    public void deleteModeDatas(String id){
        for(ModeData modeData:modeDatas){
            if(modeData.getId().equals(id)){
                modeDatas.remove(modeData);
               break;
            }
        }
    }
    public List<ModeData> getModeDatas() {
        return modeDatas;
    }

    public void setModeDatas(List<ModeData> modeDatas) {
        this.modeDatas = modeDatas;
    }


    //保存方法，与获取方法
    static File file = new File("D:/test.txt");

    //保存数据
    public static void ObjectOut(ReviewWData reviewWData) throws Exception{

        if(!file.exists()){
            file.createNewFile();
        }
        OutputStream outputStream = new FileOutputStream(file);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(reviewWData);
        outputStream.close();
        objectOutputStream.close();
    }
    //获取数据
    public static ReviewWData ObjectIn() throws Exception{
        if(!file.exists()){
            new test();
            test.main(null);
        }
        InputStream inputStream = new FileInputStream(file);
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        ReviewWData obj = (ReviewWData)objectInputStream.readObject();
        inputStream.close();
        objectInputStream.close();
        return obj;
    }
}
